<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="en" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/api.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<title>SortableCActiveRecordBehavior</title>
</head>

<body>
<div id="apiPage">

<div id="apiHeader">
<a href="http://www.yiiframework.com/extension/yiisortablemodel/">Yii Sortable Model</a> Class Reference. <a href="http://www.yiiframework.com">Yii Framework</a>
</div><!-- end of header -->

<div id="content">
<h1>SortableCActiveRecordBehavior</h1>
<div id="nav">
<a href="index.html">All Packages</a>
| <a href="#properties">Properties</a>
| <a href="#methods">Methods</a>
</div>

<table class="summaryTable docClass">
<colgroup>
	<col class="col-name" />
	<col class="col-value" />
</colgroup>
<tr>
  <th>Package</th>
  <td><a href="index.html#Yii Sortable Model">Yii Sortable Model</a></td>
</tr>
<tr>
  <th>Inheritance</th>
  <td>class SortableCActiveRecordBehavior &raquo;
<a href="http://www.yiiframework.com/doc/api/1.1/CActiveRecordBehavior">CActiveRecordBehavior</a> &raquo;
<a href="http://www.yiiframework.com/doc/api/1.1/CModelBehavior">CModelBehavior</a> &raquo;
<a href="http://www.yiiframework.com/doc/api/1.1/CBehavior">CBehavior</a> &raquo;
<a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr>
  <th>Implements</th>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/IBehavior">IBehavior</a></td>
</tr>
<tr>
  <th>Since</th>
  <td>1.1</td>
</tr>
<tr>
  <th>Source Code</th>
  <td><a class="sourceLink" href="https://github.com/laMarciana/yiiSortableModel/blob/master/models/SortableCActiveRecordBehavior.php">extensions//models/SortableCActiveRecordBehavior.php</a></td>
</tr>
</table>

<div id="classDescription">
Models having this behavior attached will automatically keep its records order consistent when items are added or deleted.</div>

<a name="properties"></a>

<div class="summary docProperty">
<h2>Public Properties</h2>

<p><a href="#" class="toggle">Hide inherited properties</a></p>

<table class="summaryTable">
<colgroup>
	<col class="col-property" />
	<col class="col-type" />
	<col class="col-description" />
	<col class="col-defined" />
</colgroup>
<tr>
  <th>Property</th><th>Type</th><th>Description</th><th>Defined By</th>
</tr>
<tr class="inherited" id="enabled">
  <td>enabled</td>
  <td>boolean</td>
  <td>whether this behavior is enabled</td>
  <td>CBehavior</td>
</tr>
<tr id="orderField">
  <td><a href="SortableCActiveRecordBehavior.html#orderField-detail">orderField</a></td>
  <td>string</td>
  <td>the field name in the database table which stores the order for the record.</td>
  <td>SortableCActiveRecordBehavior</td>
</tr>
<tr class="inherited" id="owner">
  <td>owner</td>
  <td>CComponent</td>
  <td>the owner component that this behavior is attached to.</td>
  <td>CBehavior</td>
</tr>
</table>
</div>

<a name="methods"></a>

<div class="summary docMethod">
<h2>Public Methods</h2>

<p><a href="#" class="toggle">Hide inherited methods</a></p>

<table class="summaryTable">
<colgroup>
	<col class="col-method" />
	<col class="col-description" />
	<col class="col-defined" />
</colgroup>
<tr>
  <th>Method</th><th>Description</th><th>Defined By</th>
</tr>
<tr class="inherited" id="__call">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#__call-detail">__call()</a></td>
  <td>Calls the named method which is not a class method.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="__get">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#__get-detail">__get()</a></td>
  <td>Returns a property value, an event handler list or a behavior based on its name.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="__isset">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#__isset-detail">__isset()</a></td>
  <td>Checks if a property value is null.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="__set">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#__set-detail">__set()</a></td>
  <td>Sets value of a component property.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="__unset">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#__unset-detail">__unset()</a></td>
  <td>Sets a component property to be null.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="afterConstruct">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CModelBehavior/#afterConstruct-detail">afterConstruct()</a></td>
  <td>Responds to CModel::onAfterConstruct event.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CModelBehavior">CModelBehavior</a></td>
</tr>
<tr id="afterDelete">
  <td><a href="SortableCActiveRecordBehavior.html#afterDelete-detail">afterDelete()</a></td>
  <td>Responds to CActiveRecord::onBeforeDelete event.</td>
  <td>SortableCActiveRecordBehavior</td>
</tr>
<tr class="inherited" id="afterFind">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CActiveRecordBehavior/#afterFind-detail">afterFind()</a></td>
  <td>Responds to CActiveRecord::onAfterFind event.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CActiveRecordBehavior">CActiveRecordBehavior</a></td>
</tr>
<tr class="inherited" id="afterSave">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CActiveRecordBehavior/#afterSave-detail">afterSave()</a></td>
  <td>Responds to CActiveRecord::onAfterSave event.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CActiveRecordBehavior">CActiveRecordBehavior</a></td>
</tr>
<tr class="inherited" id="afterValidate">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CModelBehavior/#afterValidate-detail">afterValidate()</a></td>
  <td>Responds to CModel::onAfterValidate event.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CModelBehavior">CModelBehavior</a></td>
</tr>
<tr class="inherited" id="asa">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#asa-detail">asa()</a></td>
  <td>Returns the named behavior object.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="attach">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CBehavior/#attach-detail">attach()</a></td>
  <td>Attaches the behavior object to the component.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CBehavior">CBehavior</a></td>
</tr>
<tr class="inherited" id="attachBehavior">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#attachBehavior-detail">attachBehavior()</a></td>
  <td>Attaches a behavior to this component.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="attachBehaviors">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#attachBehaviors-detail">attachBehaviors()</a></td>
  <td>Attaches a list of behaviors to the component.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="attachEventHandler">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#attachEventHandler-detail">attachEventHandler()</a></td>
  <td>Attaches an event handler to an event.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="beforeDelete">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CActiveRecordBehavior/#beforeDelete-detail">beforeDelete()</a></td>
  <td>Responds to CActiveRecord::onBeforeDelete event.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CActiveRecordBehavior">CActiveRecordBehavior</a></td>
</tr>
<tr class="inherited" id="beforeFind">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CActiveRecordBehavior/#beforeFind-detail">beforeFind()</a></td>
  <td>Responds to CActiveRecord::onBeforeFind event.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CActiveRecordBehavior">CActiveRecordBehavior</a></td>
</tr>
<tr id="beforeSave">
  <td><a href="SortableCActiveRecordBehavior.html#beforeSave-detail">beforeSave()</a></td>
  <td>Responds to CActiveRecord::onBeforeSave event.</td>
  <td>SortableCActiveRecordBehavior</td>
</tr>
<tr class="inherited" id="beforeValidate">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CModelBehavior/#beforeValidate-detail">beforeValidate()</a></td>
  <td>Responds to CModel::onBeforeValidate event.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CModelBehavior">CModelBehavior</a></td>
</tr>
<tr class="inherited" id="canGetProperty">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#canGetProperty-detail">canGetProperty()</a></td>
  <td>Determines whether a property can be read.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="canSetProperty">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#canSetProperty-detail">canSetProperty()</a></td>
  <td>Determines whether a property can be set.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="detach">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CBehavior/#detach-detail">detach()</a></td>
  <td>Detaches the behavior object from the component.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CBehavior">CBehavior</a></td>
</tr>
<tr class="inherited" id="detachBehavior">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#detachBehavior-detail">detachBehavior()</a></td>
  <td>Detaches a behavior from the component.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="detachBehaviors">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#detachBehaviors-detail">detachBehaviors()</a></td>
  <td>Detaches all behaviors from the component.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="detachEventHandler">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#detachEventHandler-detail">detachEventHandler()</a></td>
  <td>Detaches an existing event handler.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="disableBehavior">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#disableBehavior-detail">disableBehavior()</a></td>
  <td>Disables an attached behavior.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="disableBehaviors">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#disableBehaviors-detail">disableBehaviors()</a></td>
  <td>Disables all behaviors attached to this component.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="enableBehavior">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#enableBehavior-detail">enableBehavior()</a></td>
  <td>Enables an attached behavior.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="enableBehaviors">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#enableBehaviors-detail">enableBehaviors()</a></td>
  <td>Enables all behaviors attached to this component.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="evaluateExpression">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#evaluateExpression-detail">evaluateExpression()</a></td>
  <td>Evaluates a PHP expression or callback under the context of this component.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="events">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CActiveRecordBehavior/#events-detail">events()</a></td>
  <td>Declares events and the corresponding event handler methods.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CActiveRecordBehavior">CActiveRecordBehavior</a></td>
</tr>
<tr class="inherited" id="getEnabled">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CBehavior/#getEnabled-detail">getEnabled()</a></td>
  <td>Returns whether this behavior is enabled</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CBehavior">CBehavior</a></td>
</tr>
<tr class="inherited" id="getEventHandlers">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#getEventHandlers-detail">getEventHandlers()</a></td>
  <td>Returns the list of attached event handlers for an event.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="getOwner">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CBehavior/#getOwner-detail">getOwner()</a></td>
  <td>Returns the owner component that this behavior is attached to.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CBehavior">CBehavior</a></td>
</tr>
<tr class="inherited" id="hasEvent">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#hasEvent-detail">hasEvent()</a></td>
  <td>Determines whether an event is defined.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="hasEventHandler">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#hasEventHandler-detail">hasEventHandler()</a></td>
  <td>Checks whether the named event has attached handlers.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="hasProperty">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#hasProperty-detail">hasProperty()</a></td>
  <td>Determines whether a property is defined.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="raiseEvent">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent/#raiseEvent-detail">raiseEvent()</a></td>
  <td>Raises an event.</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a></td>
</tr>
<tr class="inherited" id="setEnabled">
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CBehavior/#setEnabled-detail">setEnabled()</a></td>
  <td>Sets whether this behavior is enabled</td>
  <td><a href="http://www.yiiframework.com/doc/api/1.1/CBehavior">CBehavior</a></td>
</tr>
</table>
</div>

<a name="events"></a>

<h2>Property Details</h2>
<div class="detailHeader" id="orderField-detail">
orderField<span class="detailHeaderTag">
property
</span>
</div>

<div class="signature">
public string <b>$orderField</b>;</div>

<p>the field name in the database table which stores the order for the record. This should be a positive integer field. Defaults to 'order'</p>


<h2>Method Details</h2>

<div class="detailHeader" id="afterDelete-detail">
afterDelete()
<span class="detailHeaderTag">
method
</span>
</div>

<table class="summaryTable">
<tr><td colspan="3">
<div class="signature2">
public void <b>afterDelete</b>(CEvent $event)</div>
</td></tr>
<tr>
  <td class="paramNameCol">$event</td>
  <td class="paramTypeCol">CEvent</td>
  <td class="paramDescCol">event parameter</td>
</tr>
</table>

<div class="sourceCode">
<b>Source Code:</b> <a class="sourceLink" href="https://github.com/laMarciana/yiiSortableModel/blob/master/models/SortableCActiveRecordBehavior.php#L65">extensions//models/SortableCActiveRecordBehavior.php#L65</a> (<b><a href="#" class="show">show</a></b>)
<div class="code"><code><span style="color: #000000">
<span style="color: #0000BB">&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">public&nbsp;function&nbsp;</span><span style="color: #0000BB">afterDelete</span><span style="color: #007700">(</span><span style="color: #0000BB">$event</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$sender&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$event</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">sender</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$model&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">call_user_func</span><span style="color: #007700">(array(</span><span style="color: #0000BB">get_class</span><span style="color: #007700">(</span><span style="color: #0000BB">$sender</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">'model'</span><span style="color: #007700">));<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$following_records&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$model</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">findAll</span><span style="color: #007700">(array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'order'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'`'</span><span style="color: #007700">.</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">orderField</span><span style="color: #007700">.</span><span style="color: #DD0000">'`&nbsp;ASC'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'condition'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'`'</span><span style="color: #007700">.</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">orderField</span><span style="color: #007700">.</span><span style="color: #DD0000">'`&nbsp;&gt;&nbsp;'</span><span style="color: #007700">.</span><span style="color: #0000BB">$sender</span><span style="color: #007700">-&gt;{</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">orderField</span><span style="color: #007700">},<br />&nbsp;&nbsp;));<br />&nbsp;&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$following_records&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$record</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$record</span><span style="color: #007700">-&gt;{</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">orderField</span><span style="color: #007700">}--;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$record</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">update</span><span style="color: #007700">();<br />&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">parent</span><span style="color: #007700">::</span><span style="color: #0000BB">afterDelete</span><span style="color: #007700">(</span><span style="color: #0000BB">$event</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;}</span>
</span>
</code></div>
</div>

<p>Responds to CActiveRecord::onBeforeDelete event.
Update records order field in a manner that their values are still successively increased by one (so, there is no gap caused by the deleted record)</p>


<div class="detailHeader" id="beforeSave-detail">
beforeSave()
<span class="detailHeaderTag">
method
</span>
</div>

<table class="summaryTable">
<tr><td colspan="3">
<div class="signature2">
public void <b>beforeSave</b>(CModelEvent $event)</div>
</td></tr>
<tr>
  <td class="paramNameCol">$event</td>
  <td class="paramTypeCol">CModelEvent</td>
  <td class="paramDescCol">event parameter</td>
</tr>
</table>

<div class="sourceCode">
<b>Source Code:</b> <a class="sourceLink" href="https://github.com/laMarciana/yiiSortableModel/blob/master/models/SortableCActiveRecordBehavior.php#L41">extensions//models/SortableCActiveRecordBehavior.php#L41</a> (<b><a href="#" class="show">show</a></b>)
<div class="code"><code><span style="color: #000000">
<span style="color: #0000BB">&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">public&nbsp;function&nbsp;</span><span style="color: #0000BB">beforeSave</span><span style="color: #007700">(</span><span style="color: #0000BB">$event</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$sender&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$event</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">sender</span><span style="color: #007700">;<br />&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$sender</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">isNewRecord</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$model&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">call_user_func</span><span style="color: #007700">(array(</span><span style="color: #0000BB">get_class</span><span style="color: #007700">(</span><span style="color: #0000BB">$sender</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">'model'</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$last_record&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$model</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">find</span><span style="color: #007700">(array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'order'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'`'</span><span style="color: #007700">.</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">orderField</span><span style="color: #007700">.</span><span style="color: #DD0000">'`&nbsp;DESC'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'limit'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$last_record</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$sender</span><span style="color: #007700">-&gt;{</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">orderField</span><span style="color: #007700">}&nbsp;=&nbsp;</span><span style="color: #0000BB">$last_record</span><span style="color: #007700">-&gt;{</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">orderField</span><span style="color: #007700">}&nbsp;+&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$sender</span><span style="color: #007700">-&gt;{</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">orderField</span><span style="color: #007700">}&nbsp;=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">parent</span><span style="color: #007700">::</span><span style="color: #0000BB">beforeSave</span><span style="color: #007700">(</span><span style="color: #0000BB">$event</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;}</span>
</span>
</code></div>
</div>

<p>Responds to CActiveRecord::onBeforeSave event.</p>


</div><!-- end of content -->

<div id="apiFooter">
Copyright &copy; 2008-2011 by <a href="http://www.yiisoft.com">Yii Software LLC</a><br/>
All Rights Reserved.<br/>
</div><!-- end of footer -->

<script type="text/javascript">
/*<![CDATA[*/
$("a.toggle").toggle(function(){
	$(this).text($(this).text().replace(/Hide/,'Show'));
	$(this).parents(".summary").find(".inherited").hide();
},function(){
	$(this).text($(this).text().replace(/Show/,'Hide'));
	$(this).parents(".summary").find(".inherited").show();
});
$(".sourceCode a.show").toggle(function(){
	$(this).text($(this).text().replace(/show/,'hide'));
	$(this).parents(".sourceCode").find("div.code").show();
},function(){
	$(this).text($(this).text().replace(/hide/,'show'));
	$(this).parents(".sourceCode").find("div.code").hide();
});
$("a.sourceLink").click(function(){
	$(this).attr('target','_blank');
});
/*]]>*/
</script>

</div><!-- end of page -->
</body>
</html>
